import request from '@/utils/request'

const baseURL = '/goods'

// 获取分类
export const getType = (id) => request.get(`/Main/getType/${id}`)

// 列处所有商品
export const getAllGoodsInfo = (businessId) => request.get(`${baseURL}/${businessId}`)

// 增加商品
export const addGoodsInfo = (goodsForm, businessId) =>
  request.post(`${baseURL}/addGoods/${businessId}`, goodsForm, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })

// 获取主页商品
export const getMajorGoods = () => request.get(`${baseURL}`)

// 获取商品信息
export const getGoodsInfo = (id) => request.get(`${baseURL}/getOneGoodsInfo/${id}`)

// 更新商品信息
export const updateGoodsInfo = (goodsForm, id) =>
  request.post(`${baseURL}/updateGoodsInfo/${id}`, goodsForm)

// 删除指定商品
export const deleteGoodsInfo = (id) => request.post(`${baseURL}/deleteGoodsInfo/${id}`)

// 查询商品数量
export const getGoodsSum = (id) =>
  request.get(`${baseURL}/selectsum`, {
    params: {
      id
    }
  })

// 更新商品数量
export const updateGoodsSum = (id, num) =>
  request.get(`${baseURL}/updateGoodsSum/${id}`, {
    params: {
      consumeNum: num
    }
  })

// 获取评论
export const getAllComment = (goodsId) => request.get(`${baseURL}/getComment/${goodsId}`)

// 发布评论
export const addComment = (commentInfo) => request.post(`${baseURL}/addComment`, commentInfo)

// 获取商店名
export const getBusinessName = (id) => request.get(`${baseURL}/getBusinessName/${id}`)

// 搜索商品
export const searchGoodsInfo = (name, orderBy) =>
  request.get(`${baseURL}/searchgoods`, {
    params: {
      name,
      orderBy
    }
  })
